﻿<Window x:Class="ZX_AAA_Workshop.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:s="clr-namespace:System;assembly=mscorlib"
        xmlns:sd="clr-namespace:System.Diagnostics;assembly=System"
        xmlns:l="clr-namespace:ZX_AAA_Workshop"
        Title="{Binding Source={x:Static l:Window1.AppVersion}, StringFormat=ZX AAA Workshop \{0\}}"
        Height="520" Width="400"
        Name="Window"
        MouseMove="Window_MouseMove" MouseUp="Window_MouseUp">
  <!--Icon="fafa.ico"-->
  <Window.Resources>
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    <ObjectDataProvider x:Key="testProvider" ObjectType="sd:Process" MethodName="GetProcessesByName">
      <ObjectDataProvider.MethodParameters>
        <s:String>devenv</s:String>
      </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
    <!--<Style TargetType="Window">
      <Setter Property="Background" Value="Black"/>
    </Style>
    <Style TargetType="Button">
      <Setter Property="Background" Value="#222"/>
      <Setter Property="Foreground" Value="#ccc"/>
    </Style>-->
    <Style TargetType="TextBox">
      <!--<Setter Property="Background" Value="Transparent"/>
      <Setter Property="Foreground" Value="#eee"/>-->
      <Setter Property="Padding" Value="0"/>
      <Setter Property="BorderThickness" Value="0"/>
    </Style>
    <l:NegateBooleanConverter x:Key="NegateBooleanConverter"/>
    <l:NotEmptyToBooleanConverter x:Key="NotEmptyToBooleanConverter"/>
    <!--<l:WindowSizeConverter x:Key="WindowSizeConverter"/>-->
  </Window.Resources>
  <ScrollViewer Name="scroll" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Hidden">
    <ScrollViewer.Resources>
      <Style TargetType="Border">
        <Setter Property="BorderBrush" Value="#aaa"/>
        <Setter Property="BorderThickness" Value="2"/>
        <Setter Property="CornerRadius" Value="4"/>
      </Style>
    </ScrollViewer.Resources>
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition Width="0"/>
        <ColumnDefinition Width="300"/>
      </Grid.ColumnDefinitions>
      <Grid Width="{Binding ElementName=scroll, Path=ActualWidth}" Name="snapshotPane">
        <DockPanel Margin="10">
          <StackPanel DockPanel.Dock="Top">
            <!--<Button Name="FindEmulatorButton" HorizontalAlignment="Right" Click="FindEmulatorButton_Click">Обновить</Button>-->
            <DockPanel>
              <Button Name="FindEmulatorButton" DockPanel.Dock="Right" Click="FindEmulatorButton_Click" VerticalAlignment="Bottom">Обновить</Button>
              <TextBlock Foreground="#555" TextWrapping="Wrap" Text="Убедись, что окна эмуляторов видны и ничем не перекрываются" VerticalAlignment="Center"/>
            </DockPanel>
            <!--<ListView Name="Emulators" SelectionMode="Extended"
                    ItemsSource="{Binding Source={StaticResource testProvider}}">
              <ListView.View>
                <GridView>
                  <GridViewColumn Header="Имя" DisplayMemberBinding="{Binding ProcessName}"/>
                  <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Id}"/>
                  <GridViewColumn Header="Заголовок" DisplayMemberBinding="{Binding MainWindowTitle}"/>
                </GridView>
              </ListView.View>
            </ListView>-->
          </StackPanel>
          <StackPanel DockPanel.Dock="Bottom">
            <DockPanel LastChildFill="False">
              <CheckBox DockPanel.Dock="Left" VerticalAlignment="Center" Name="WithBorder" Content="С бордером" Click="WithBorder_Click">
                <CheckBox.Foreground>
                  <SolidColorBrush x:Name="WithBorder_Brush" Color="#555"/>
                </CheckBox.Foreground>
                <CheckBox.Triggers>
                  <EventTrigger RoutedEvent="CheckBox.Checked">
                    <BeginStoryboard Name="withBorderAnimation">
                      <Storyboard RepeatBehavior="Forever">
                        <ColorAnimation Storyboard.TargetName="WithBorder_Brush" Storyboard.TargetProperty="Color"
                          BeginTime="0:0:0.0" Duration="0:0:0.3" From="#f00" To="#0f0"/>
                        <ColorAnimation Storyboard.TargetName="WithBorder_Brush" Storyboard.TargetProperty="Color"
                          BeginTime="0:0:0.3" Duration="0:0:0.3" From="#0f0" To="#00f"/>
                        <ColorAnimation Storyboard.TargetName="WithBorder_Brush" Storyboard.TargetProperty="Color"
                          BeginTime="0:0:0.6" Duration="0:0:0.3" From="#00f" To="#f00"/>
                      </Storyboard>
                    </BeginStoryboard>
                  </EventTrigger>
                  <EventTrigger RoutedEvent="CheckBox.Unchecked">
                    <RemoveStoryboard BeginStoryboardName="withBorderAnimation"/>
                  </EventTrigger>
                </CheckBox.Triggers>
              </CheckBox>
              <ToggleButton DockPanel.Dock="Right" Name="EmulatorsButton" Content="Настройки &gt;&gt;" Click="EmulatorsButton_Click"/>
            </DockPanel>
            <DockPanel>
              <TextBlock DockPanel.Dock="Top" Foreground="#555" Text="Папка, куда будут сохраняться снимки:" Margin="0,8"/>
              <Button Name="BrowseButton" DockPanel.Dock="Right" Click="BrowseButton_Click" Margin="4,0,0,0">Выбрать...</Button>
              <Border>
                <TextBox Name="SavePath" />
              </Border>
            </DockPanel>
            <Button Name="SnapshotButton" Margin="15" Background="LightSkyBlue" Click="SnapshotButton_Click" FontSize="15" HorizontalAlignment="Center" Padding="20,4">Сохранить снимок</Button>
          </StackPanel>
          <Border Margin="0,4">
            <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
              <ItemsControl Name="Snapshots">
                <ItemsControl.Template>
                  <ControlTemplate>
                    <Grid>
                      <StackPanel IsItemsHost="True"/>
                      <StackPanel Name="NoItemsText" Visibility="Hidden" VerticalAlignment="Center" HorizontalAlignment="Center"
                                  TextElement.FontSize="15">
                        <TextBox TextElement.Foreground="#555" IsReadOnly="True" TextWrapping="Wrap">Не найден ни один из поддерживаемых эмуляторов.</TextBox>
                        <!--<ItemsControl TextElement.Foreground="#555" ItemsSource="{Binding Source={x:Static l:Window1.SupportedEmulators}}" Margin="10,10,0,0"/>-->
                        <!--<ItemsControl ItemsSource="{Binding Source={x:Static l:Window1.SnapshotDefinitions}}" Margin="10">
                          <ItemsControl.ItemTemplate>
                            <DataTemplate DataType="l:SnapshotDefinition">
                              <TextBox IsReadOnly="True" Foreground="#555">
                                <TextBox.Text>
                                  <MultiBinding StringFormat="{}{0} ({1}x{2})">
                                    <Binding Path="ProcessName"/>
                                    <Binding Path="SnapshotRect.Width"/>
                                    <Binding Path="SnapshotRect.Height"/>
                                  </MultiBinding>
                                </TextBox.Text>
                              </TextBox>
                            </DataTemplate>
                          </ItemsControl.ItemTemplate>
                        </ItemsControl>-->
                      </StackPanel>
                    </Grid>
                    <ControlTemplate.Triggers>
                      <DataTrigger Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Items.Count}" Value="0">
                        <Setter TargetName="NoItemsText" Property="Visibility" Value="Visible"/>
                      </DataTrigger>
                    </ControlTemplate.Triggers>
                  </ControlTemplate>
                </ItemsControl.Template>
                <ItemsControl.ItemTemplate>
                  <DataTemplate>
                    <StackPanel Margin="6">
                      <TextBox IsReadOnly="True" Text="{Binding WindowTitle}" FontSize="15" TextWrapping="Wrap" Margin="0,4,0,0">
                        <TextBox.ToolTip>
                          <TextBlock>
                            <TextBlock.Text>
                              <MultiBinding StringFormat="{}Размер экрана: {0}x{1}, бордер: {2}">
                                <Binding Path="Definition.WindowRect.Width" Mode="OneWay"/>
                                <Binding Path="Definition.WindowRect.Height" Mode="OneWay"/>
                                <Binding Path="Definition.Border" Mode="OneWay"/>
                              </MultiBinding>
                            </TextBlock.Text>
                          </TextBlock>
                        </TextBox.ToolTip>
                      </TextBox>
                      <WrapPanel Orientation="Horizontal">
                        <TextBox IsReadOnly="True" TextWrapping="Wrap" Foreground="#555" Margin="0,4,0,0">
                          <TextBox.Text>
                            <MultiBinding StringFormat="{}{0}  {1}.{2}">
                              <Binding Path="SizeString" Mode="OneWay"/>
                              <Binding Path="FileName" Mode="OneWay"/>
                              <Binding ElementName="Window" Path="Settings.ImageFormat" Mode="OneWay"/>
                            </MultiBinding>
                          </TextBox.Text>
                        </TextBox>
                        <TextBox IsReadOnly="True" TextWrapping="Wrap" Foreground="OrangeRed" Margin="4,4,0,0" Text="(c бордером)"
                                 Visibility="{Binding ElementName=WithBorder, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                      </WrapPanel>
                      <TextBox IsReadOnly="True" TextWrapping="Wrap" Name="comment" Foreground="Red" Text="{Binding Comment}"/>
                      <Image Source="{Binding WpfBitmapSource}" StretchDirection="DownOnly" HorizontalAlignment="Left" Margin="6">
                        <Image.Effect>
                          <DropShadowEffect Color="#aaa" ShadowDepth="5" BlurRadius="10"/>
                        </Image.Effect>
                      </Image>
                      <!--<TextBox IsReadOnly="True" TextWrapping="Wrap" Foreground="#555" Text="{Binding FileName, Mode=OneWay}" Margin="0,4,0,0"/>-->
                    </StackPanel>
                    <DataTemplate.Triggers>
                      <DataTrigger Binding="{Binding Comment}" Value="{x:Null}">
                        <Setter TargetName="comment" Property="Visibility" Value="Collapsed"/>
                      </DataTrigger>
                    </DataTemplate.Triggers>
                  </DataTemplate>
                </ItemsControl.ItemTemplate>
                <!--<ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                  <UniformGrid />
                </ItemsPanelTemplate>
              </ItemsControl.ItemsPanel>-->
                <!--<l:Snapshot WindowTitle="Unreal" Comment="Не найдено окно подходящего размера (640x480 или 320x240). Попробуй выбрать другой размер окна"
                            WpfBitmapSource="c:\Works\z80\Projects\ZX AAA Workshop\ZX AAA Workshop\bin\Release\unreal5.png"
                            FileName="unreal5.png">
                  <l:Snapshot.Definition>
                    <l:SnapshotDefinition WindowSize="320,240"/>
                  </l:Snapshot.Definition>
                </l:Snapshot>-->
              </ItemsControl>
            </ScrollViewer>
          </Border>
        </DockPanel>
      </Grid>
      <!--<GridSplitter Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Center" Width="2" Margin="3,0"/>-->
      <Grid Grid.Column="2" Name="emulatorsPane">
        <DockPanel Margin="10">
          <!-- Visibility="{Binding ElementName=EmulatorsButton, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"-->
          <DockPanel DockPanel.Dock="Top">
            <!--<Button Content="&lt;&lt; Назад" Margin="0,0,4,0"/>-->
            <ToggleButton Name="AddEmulatorButton" DockPanel.Dock="Right" Margin="0,4"  Content="Добавить эмулятор" Checked="AddEmulatorButton_Checked"
                        IsEnabled="{Binding IsChecked, Converter={StaticResource NegateBooleanConverter}, RelativeSource={x:Static RelativeSource.Self}}"/>
            <TextBlock Foreground="#555" Text="Поддерживаемые эмуляторы" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,4"/>
          </DockPanel>
          <Border DockPanel.Dock="Bottom" Padding="4" Margin="0,4">
            <StackPanel>
              <DockPanel LastChildFill="False">
                <TextBlock DockPanel.Dock="Left" Foreground="#555" Text="Формат снимка:" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,4"/>
                <ComboBox Name="imageFormatSelector" DockPanel.Dock="Left" Width="60" Margin="4,0,0,0"
                        ItemsSource="{Binding ElementName=Window, Path=ImageFormats}"
                        SelectedItem="{Binding ElementName=Window, Path=Settings.ImageFormat, Mode=TwoWay}"
                        SelectionChanged="imageFormatSelector_SelectionChanged"></ComboBox>
              </DockPanel>
              <CheckBox Content="Задавать имя файла вручную" Margin="0,4,0,4"
                        IsChecked="{Binding ElementName=Window, Path=Settings.IsManualFileName, Mode=TwoWay}"
                        Click="CheckBox_Click"/>
            </StackPanel>
          </Border>
          <Grid DockPanel.Dock="Bottom"
                Visibility="{Binding ElementName=AddEmulatorButton, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}">
            <DockPanel LastChildFill="False" Margin="0,8">
              <DockPanel DockPanel.Dock="Top">
                <Border DockPanel.Dock="Right">
                  <Grid Width="50" Height="40" Name="Finder">
                    <Ellipse Width="20" Height="20" MouseDown="Ellipse_MouseDown" Stroke="White" StrokeThickness="2">
                      <Ellipse.Effect>
                        <DropShadowEffect ShadowDepth="3" BlurRadius="10"/>
                      </Ellipse.Effect>
                      <Shape.Style>
                        <Style TargetType="Shape">
                          <Setter Property="Fill" Value="Green"/>
                          <!--<Setter Property="Fill">
                            <Setter.Value>
                              <RadialGradientBrush GradientOrigin="0.7,0.3">
                                <RadialGradientBrush.GradientStops>
                                  <GradientStop Color="White" Offset="0"/>
                                  <GradientStop Color="Green" Offset="0.8"/>
                                  <GradientStop Color="Green" Offset="1"/>
                                </RadialGradientBrush.GradientStops>
                              </RadialGradientBrush>
                            </Setter.Value>
                          </Setter>-->
                          <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                              <Setter Property="Fill" Value="LimeGreen"/>
                            </Trigger>
                          </Style.Triggers>
                        </Style>
                      </Shape.Style>
                    </Ellipse>
                  </Grid>
                </Border>
                <TextBlock Foreground="#555" Text="Перетащи зеленую точку на окно эмулятора, или задай параметры вручную" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,4"/>
              </DockPanel>
              <DockPanel DockPanel.Dock="Top" Margin="0,4" Grid.IsSharedSizeScope="True" Name="EmulatorProperties" DataContext="{Binding ElementName=Window, Path=NewEmulatorParameters}">
                <FrameworkElement.Resources>
                  <Style TargetType="TextBlock">
                    <Setter Property="VerticalAlignment" Value="Center"/>
                    <Setter Property="Foreground" Value="#555"/>
                  </Style>
                  <Style TargetType="TextBox">
                    <Setter Property="BorderThickness" Value="1"/>
                    <Setter Property="BorderBrush" Value="#aaa"/>
                    <Setter Property="Margin" Value="4,1,0,1"/>
                    <Setter Property="Template">
                      <Setter.Value>
                        <ControlTemplate>
                          <Border BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}"
                                  Background="{TemplateBinding Background}" Name="Bd" SnapsToDevicePixels="True"
                                  CornerRadius="4">
                            <ScrollViewer Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                          </Border>
                        </ControlTemplate>
                      </Setter.Value>
                    </Setter>
                  </Style>
                </FrameworkElement.Resources>
                <Grid DockPanel.Dock="Top">
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="a"/>
                    <ColumnDefinition/>
                  </Grid.ColumnDefinitions>
                  <TextBlock Text="Имя процесса:"/>
                  <TextBox Text="{Binding ProcessName}" Grid.Column="1" Name="ProcessNameBox"/>
                </Grid>
                <Grid DockPanel.Dock="Top">
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="a"/>
                    <ColumnDefinition/>
                  </Grid.ColumnDefinitions>
                  <TextBlock Text="Размер окна:"/>
                  <TextBox Grid.Column="1" Text="{Binding WindowSize}" ToolTip="Ширина,Высота"/>
                  <!--<TextBox Grid.Column="1">
                    <TextBox.Text>
                      <MultiBinding StringFormat="{}{0}x{1}">
                        <Binding Path="WindowRect.Width" Mode="OneWay"/>
                        <Binding Path="WindowRect.Height" Mode="OneWay"/>
                      </MultiBinding>
                    </TextBox.Text>
                  </TextBox>-->
                </Grid>
                <Grid DockPanel.Dock="Top">
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="a"/>
                    <ColumnDefinition/>
                  </Grid.ColumnDefinitions>
                  <TextBlock Text="Бордер:"/>
                  <TextBox Grid.Column="1" Text="{Binding Border}"/>
                </Grid>
                <Grid DockPanel.Dock="Top">
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="a"/>
                    <ColumnDefinition/>
                  </Grid.ColumnDefinitions>
                  <TextBlock Text="Область без бордера:"/>
                  <TextBox Grid.Column="1" Text="{Binding SnapshotRect}" ToolTip="Отступ слева,Отступ сверху,Ширина,Высота"/>
                </Grid>
                <Grid DockPanel.Dock="Top">
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="a"/>
                    <ColumnDefinition/>
                  </Grid.ColumnDefinitions>
                  <TextBlock Text="Область с бордером:"/>
                  <TextBox Grid.Column="1" Text="{Binding CalcWithBorderRect}" ToolTip="Отступ слева,Отступ сверху,Ширина,Высота"/>
                </Grid>
                <Grid DockPanel.Dock="Top">
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="a"/>
                    <ColumnDefinition/>
                  </Grid.ColumnDefinitions>
                  <TextBlock Text="Формат заголовка:"/>
                  <TextBox Grid.Column="1" Text="{Binding WindowTitleFormat}"/>
                </Grid>
              </DockPanel>
              <Grid DockPanel.Dock="Top">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition/>
                  <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Button Name="AddOk_Button" Content="Добавить" Click="AddOk_Button_Click" IsEnabled="{Binding ElementName=ProcessNameBox, Path=Text, Converter={StaticResource NotEmptyToBooleanConverter}}"/>
                <Button Name="AddCancel_Button" Content="Отмена" Click="AddCancel_Button_Click" Grid.Column="1"/>
              </Grid>
            </DockPanel>
          </Grid>
          <Border>
            <ScrollViewer HorizontalScrollBarVisibility="Auto" Name="EmulatorsListScrollViewer">
              <ItemsControl ItemsSource="{Binding ElementName=Window, Path=SnapshotDefinitions}" Name="EmulatorsList">
                <ItemsControl.ItemTemplate>
                  <DataTemplate>
                    <DataTemplate.Resources>
                      <Style TargetType="TextBlock">
                        <Setter Property="Margin" Value="4,0"/>
                        <Setter Property="Foreground" Value="#555"/>
                      </Style>
                    </DataTemplate.Resources>
                    <StackPanel Margin="0,4">
                      <TextBox FontSize="14" IsReadOnly="True" Text="{Binding ProcessName}"/>
                      <!--<TextBox IsReadOnly="True" Text="{Binding WindowRect.X}"/>
                      <TextBox IsReadOnly="True" Text="{Binding WindowRect.Y}"/>
                      <TextBox IsReadOnly="True" Text="{Binding WindowRect.Width}"/>
                      <TextBox IsReadOnly="True" Text="{Binding WindowRect.Height}"/>-->
                      <StackPanel Margin="8,0">
                        <StackPanel Orientation="Horizontal">
                          <TextBlock Text="Размер окна:"/>
                          <TextBox IsReadOnly="True">
                            <TextBox.Text>
                              <MultiBinding StringFormat="{}{0}x{1}">
                                <Binding Path="WindowRect.Width" Mode="OneWay"/>
                                <Binding Path="WindowRect.Height" Mode="OneWay"/>
                              </MultiBinding>
                            </TextBox.Text>
                          </TextBox>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                          <TextBlock Text="Бордер:"/>
                          <TextBox IsReadOnly="True" Text="{Binding Border}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                          <TextBlock Text="Область без бордера:"/>
                          <TextBox IsReadOnly="True" Text="{Binding SnapshotRect}" ToolTip="Отступ слева,Отступ сверху,Ширина,Высота"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                          <TextBlock Text="Область с бордером:"/>
                          <TextBox IsReadOnly="True" Text="{Binding CalcWithBorderRect}" ToolTip="Отступ слева,Отступ сверху,Ширина,Высота"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                          <TextBlock Text="Формат заголовка:"/>
                          <TextBox IsReadOnly="True" Text="{Binding WindowTitleFormat}"/>
                        </StackPanel>
                      </StackPanel>
                    </StackPanel>
                  </DataTemplate>
                </ItemsControl.ItemTemplate>
                <!--<l:SnapshotDefinition ProcessName="Unreal" WindowRect="0,0,640,480"
                                      SnapshotRect="64,64,256,192" WithBorderRect="16,16,356,275"
                                      Border="Complete" WindowTitleFormat="{}{filename} - {}"/>-->
              </ItemsControl>
            </ScrollViewer>
          </Border>
        </DockPanel>
      </Grid>
      <!--<Border BorderBrush="#222" BorderThickness="1" Background="White" Margin="4">
        <Border.BitmapEffect>
          <DropShadowBitmapEffect Color="Black" ShadowDepth="5" Softness="1"/>
        </Border.BitmapEffect>
      </Border>-->
    </Grid>
  </ScrollViewer>
</Window>
